<%--
  Created by IntelliJ IDEA.
  User: carol
  Date: 2018/6/12
  Time: 17:23
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page language="java" import="java.util.*,javax.servlet.*,functest.*" pageEncoding="utf-8" %>
<html>
<head>
    <title>城市与机场管理页面</title>
    <meta charset="UTF-8">
    <script type="text/javascript" src="js/jquery-3-2-1.js"></script>
    <link type="text/css" rel="stylesheet" href="layui/css/layui.css" media="all">
    <script type="text/javascript" src="layui/layui.all.js"></script>
    <link type="text/css" rel="stylesheet" href="css/style.css" media="all">
</head>
<body>
<div class="head" >
    <div class="head-text">
        <li class="title">航空票务系统</li>
    </div>
    <a href="index.jsp"><img class="logo" src="img/logo.png" ></a>
</div>
<div style="margin-top: 100px;">
    <ul class="layui-nav layui-nav-tree layui-nav-side" style="top: 60;">
        <li class="layui-nav-item layui-nav-itemed">
            <a href="mgrcity.jsp">城市机场管理</a>
        </li>
        <li class="layui-nav-item">
            <a href="mgrtk.jsp">票务信息管理</a>
        </li>
        <li class="layui-nav-item"><a href="mgrflight.jsp">航班管理</a></li>
    </ul>
    <div style="margin-left: 220px;margin-right: 20px">
        <blockquote class="layui-elem-quote">城市信息</blockquote>
        <table lay-filter="citytable">
            <thead>
            <tr>
                <th lay-data="{field:'cityid',align:'center'}">城市ID</th>
                <th lay-data="{field:'cityname',align:'center'}">城市名</th>
                <th lay-data="{field:'airport',align:'center'}">拥有机场</th>
                <th lay-data="{fixed: 'right', minWidth: 220, align:'center', toolbar: '#barcity'}">操作</th>
            </tr>
            </thead>
            <tbody>
            <%
                int count = 100;
                FindAPrint func =new FindAPrint();
                List<String> cityname=func.Findcitys();
                for(String attribute : cityname) {
                    count++;
                    out.println("<tr><td>"+count+"</td><td>" + attribute + "</td><td>");
                    List<String> airport = func.Findjcs(attribute);
                    for (String temp : airport){
                        out.println(temp + " ");
                    }
                    out.println("</td><td></td></tr>");
                }
            %>
            </tbody>
        </table>
        <div style="text-align: center">
            <button class="layui-btn layui-btn-primary" id="addcity">添加城市</button>
            <a href="index.jsp" class="layui-btn layui-btn-normal">返回</a>
        </div>
    </div>
</div>



</body>
</html>

<script type="text/html" id="barcity">
    <a class="layui-btn layui-btn-radius layui-btn-primary layui-btn-xs" lay-event="add">添加机场</a>
    <a class="layui-btn layui-btn-radius layui-btn-xs" lay-event="edit">编辑城市机场</a>
    <a class="layui-btn layui-btn-radius layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>
<script type="text/javascript">
    layui.use(['jquery','layer','table'], function(){
        var layer = layui.layer
            ,element = layui.element
            ,$= layui.$
            ,table=layui.table;

        //转换静态表格
        table.init('citytable', {limit: 10,page:true});
        //监听工具条
        table.on('tool(citytable)', function(obj){
            var data = obj.data;
            var city_id = data['cityid'];
            var city_oldname = data['cityname'];
            editurl = 'editcity.jsp?cityid=' + city_id +"&cityoldname="+city_oldname;
            addurl = 'addport.jsp?cityid='+ city_id + "&cityoldname="+city_oldname;
            delurl = 'changecity.jsp?action=del&cityid=';
            delurl = delurl + city_id;
            if(obj.event === 'edit'){
                layer.open({
                    type: 2,
                    title: "编辑城市",
                    content: editurl,
                    area: [window.innerWidth * 1.5 / 3 + "px", window.innerHeight * 2 / 3 + "px"],
                });
            }
            else if(obj.event === 'add'){
                layer.open({
                    type: 2,
                    title: "添加机场",
                    content: addurl,
                    area: [window.innerWidth * 1.5 / 3 + "px", window.innerHeight * 15 / 30 + "px"],
                });
            }
            else if(obj.event === 'del'){
                layer.confirm('确定删除城市？', function(index){
                    if (obj.data["airport"].replace(/(^s*)|(s*$)/g, "").length > 1){
                        layer.msg('删除失败,机场不为空', {
                            icon: 5,
                            time: 500 //2秒关闭（如果不配置，默认是3秒）
                        },);
                    }
                    else {
                        $.get(delurl);
                        obj.del();
                        layer.msg('删除成功', {
                            icon: 6,
                            time: 500 //2秒关闭（如果不配置，默认是3秒）
                        },);
                    }


                    layer.close(index);
                });
            }
        });
        $("#addcity").click(function (){
            addcityurl = "changecity.jsp?action=add";
            layer.open({
                type: 2,
                title: "添加城市",
                content: addcityurl,
                area: [window.innerWidth * 1.5 / 3 + "px", window.innerHeight * 26 / 30 + "px"],
            });
        });
    });
</script>
